package com.frkj.yuan.utils;
import com.frkj.yuan.base.BaseService;
import com.frkj.yuan.main.ConstantStaticUrl;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
/**
 * Retrofit 网络请求工具类封装
 */
public class RetrofitUtil {
    private volatile static RetrofitUtil sInstance;
    private Retrofit mRetrofit;
    private BaseService mService;
    public RetrofitUtil() {
        mRetrofit = new Retrofit.Builder()
                .baseUrl(ConstantStaticUrl.BASE_URL).client(new OkHttpClient.Builder().addInterceptor(new LogInterceptor())
                        .callTimeout(30000, TimeUnit.MILLISECONDS)
                        .readTimeout(30000, TimeUnit.MILLISECONDS)
                        .build())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        mService = mRetrofit.create(BaseService.class);
    }
    public static RetrofitUtil getInstance(){
        if (sInstance == null){
            synchronized(RetrofitUtil.class){
                if (sInstance == null){
                    sInstance = new RetrofitUtil();
                }
            }
        }
        return sInstance;
    }
    public BaseService getmService(){
        return mService;
    }

}
